package com.starsea.book.ui.newpage.weidget.banner.transformer

import android.view.View
import androidx.core.view.ViewCompat

/**
 * 描述:
 */
class FlipPageTransformer : BannerPageTransformer() {
  override fun handleInvisiblePage(view: View, position: Float) {}
  override fun handleLeftPage(view: View, position: Float) {
    ViewCompat.setTranslationX(view, -view.width * position)
    val rotation = ROTATION * position
    ViewCompat.setRotationY(view, rotation)
    if (position > -0.5) {
      view.visibility = View.VISIBLE
    } else {
      view.visibility = View.INVISIBLE
    }
  }

  override fun handleRightPage(view: View, position: Float) {
    ViewCompat.setTranslationX(view, -view.width * position)
    val rotation = ROTATION * position
    ViewCompat.setRotationY(view, rotation)
    if (position < 0.5) {
      view.visibility = View.VISIBLE
    } else {
      view.visibility = View.INVISIBLE
    }
  }

  companion object {
    private const val ROTATION = 180.0f
  }
}